<?php

class Core_Template
{


    private $_css_file;

    private $_js_file;

    private $_title;

    private $_smarty;

    public  function  __construct()
    {
        require PRJ.'Smarty'.DS.'libs'.DS.'Smarty.class.php';
        $this->_smarty = new Smarty();
        //$this->smarty->caching = false;

        $this->_smarty->template_dir = APP.'Views'.DS;

        $this->_smarty->compile_dir = APP.'Views'.DS.'templates_c'.DS;
        $this->_smarty->cache_dir = APP.'Views'.DS.'cache'.DS;
        $this->_smarty->config_dir = APP.'Views'.DS.'configs'.DS;
    }

 

    public function add_css_file($file_name)
    {

        if (!is_array($file_name)) {
            return false;
        }

        foreach ($file_name as $value) {
            $value = ltrim($value,'/');
            if (!is_file(PRJ . $value)) {
                return false;
            } else {
                if (empty($this->_css_file)) {
                    $this->_css_file =  '/' .$value ;
                } else {
                    $this->_css_file = $this->_css_file . PATH_SEPARATOR . '/' .$value;
                }
            }
        }

        return true;
    }

    public function get_css_file()
    {
        return explode(PATH_SEPARATOR, $this->_css_file);
    }

    public function get_js_file()
    {
    RETURN explode(PATH_SEPARATOR, $this->_js_file);
    }

    public function add_js_file($file_name)
    {
        if (!is_array($file_name)) {
            return false;
        }

        foreach ($file_name as $value) {
            $value = ltrim($value,'/');
            
            if (!is_file(PRJ . $value)) {
                return false;
            } else {
                if (empty($this->_js_file)) {
                    $this->_js_file =  '/' .$value ;
                } else {
                    $this->_js_file = $this->_js_file . PATH_SEPARATOR . '/' .$value;
                }
            }
        }
        return true;
    }

    public function set_title($title)
    {
        $this->_title = $title;
    }

    public function get_title()
    {
        return $this->_title;
    }

    public function get_smarty()
    {
        return $this->_smarty;
    }

    public function error_page()
    {
        header('404 !');
        exit (file_get_contents(PRJ . '404.html'));
    }

   
}
?>
